local class = reload("class")
local midws = reload("global.midws")

---@class enable @功能开关(活动除外)
local this = class()

function this:ctor()
    self:launch()
end

function this:launch()
    local key = string.format("global:set:%d:enable", midws.rdb.zone)
    local arg = {
        enable = {}, ---功能开启
        rdbKey = key
    }
    midws.rdb:smembers(key)(self.coback, self, arg)
    local list = self:await()
    for _, k in ipairs(list) do
        arg.enable[k] = true
    end
    self._arg = arg
end

---启用功能
function this:enable(key)
    local arg = self._arg
    arg.enable[key] = true
    arg.rdb:sadd(arg.rdbKey, key)
end

---禁用功能
function this:disable(key)
    local arg = self._arg
    arg.enable[key] = nil
    arg.rdb:srem(arg.rdbKey, key)
end

---判断启用
function this:get(key)
    local arg = self._arg
    return arg.enable[key] or false
end

return this

--[[
    global:set:zone:enable = {
        [key]---true:功能开启 false:功能关闭
    }
]]
